﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Routing;
using System.Web;

namespace MyClub.Web.Routing
{
    /// <summary>
    /// Provides a base implementing <see cref="IRouteHandler"/>
    /// </summary>
    public abstract class RouteHandler: IRouteHandler
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="RouteHandler"/> class.
        /// </summary>
        protected RouteHandler()
        {
        }

        /// <summary>
        /// Provides the object that processes the request.
        /// </summary>
        /// <param name="requestContext">An object that encapsulates information about the request.</param>
        /// <returns>An object that processes the request.</returns>
        public System.Web.IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            if (requestContext == null)
                throw new ArgumentNullException("requestContext");

            IHttpHandler httpHandler = CreateHttpHandler(requestContext);
            httpHandler.AssignRequestContext(requestContext);
            return httpHandler;
        }

        /// <summary>
        /// Creates the HTTP handler.
        /// </summary>
        /// <param name="requestContext">The request context.</param>
        /// <returns>An instance that implements the <see cref="IHttpHandler"/>.</returns>
        protected abstract IHttpHandler CreateHttpHandler(RequestContext requestContext);
    }
}
